<template>
  <div class="top-tab-box">
    <div class="top-tab-wrapper" :style="{ top: top }">
      <div class="wrap">
        <div
          class="item"
          :class="{ active: current == index }"
          v-for="(item, index) in list"
          :key="index"
          @click="changeTab(index)"
        >
          <div class="te">
            <div class="cn">
              {{ item.cn }}
            </div>
            <div class="en">
              {{ item.en }}
            </div>
          </div>
          <div class="line-box">
            <div class="top-line"></div>
            <div class="bottom-line"></div>
          </div>
        </div>
      </div>
    </div>
    <div style="height: 126rpx"></div>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, getCurrentInstance, onMounted, watch, computed, defineEmits, defineProps } from 'vue'

import { useStore } from 'vuex'
const store = useStore()
const emit = defineEmits(['change'])
const props = defineProps({
  list: {
    type: Array,
    default: () => []
  },
  current: {
    type: Number,
    default: 0
  }
})
const changeTab = (index: number) => {
  console.log('选项切换', index)
  emit('change', index)
  // 切换选项时,要把页面等数据置空
}

let top = ref<number>(0)
const statusBarHeight = computed(() => store.getters['system/statusBarHeight'])
top = `calc(${statusBarHeight.value}px + 90rpx)`
console.log('距离顶部据里', top)
</script>

<style lang="scss">
.top-tab-box {
  .top-tab-wrapper {
    position: fixed;
    width: 100%;
    left: 0;
    background: #ececec !important;
  }
  .wrap {
    display: flex;
    justify-content: space-between;
    .item {
      flex: 1;
      margin-right: 10rpx;
      .te {
        font-size: 24rpx;
        color: #000;
        font-family: Helvetica;
      }
      .cn {
        line-height: 36rpx;
      }
      .en {
        line-height: 44rpx;
      }
      .line-box {
        .bottom-line,
        .top-line {
          height: 14rpx;
          background: #000;
          margin-bottom: 4rpx;
        }
        .bottom-line {
          transform: translateY(-18rpx);
          opacity: 0;
          transition: all 0.1s ease;
        }
      }
      &:last-child {
        margin-right: 0;
      }
    }
    .item.active {
      .line-box {
        .bottom-line {
          transform: translateY(0);
          opacity: 1;
        }
      }
    }
  }
}
</style>
